(function($){
    $.fn.extend({
        popup : function(){
            var oBody = $('body');
            var oBtn = $('.btn');
            var onOff = true;

            oBtn.click(function () {
                if (onOff){
                    var disX = 0;
                    var disY = 0;
                    onOff = false;
                    var oPop = $('<div class="popup"></div>');
                    oBody.append(oPop);
                    var oRemove = $('<div class="remove">X</div>');
                    oPop.append(oRemove);

                      oPop.mousedown(function(ev){

                        disX = ev.pageX - $(this).offset().left;
                        disY = ev.pageY - $(this).offset().top;

                        $(document).mousemove(function(ev){

                            oPop.css('left',ev.pageX - disX);
                            oPop.css('top',ev.pageY - disY);

                        });

                        $(document).mouseup(function(){

                            $(document).off();

                        });



                    });

                    oRemove.click(function () {
                        oPop.remove();
                        onOff = true;
                    });
                }


            });
        }
    });
})(jQuery);






